package com.jp.kefu.web.proxy;

import com.jp.kefu.service.TokenService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * @author lijin
 */
@Component
public class ApiProxy {

    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private RestTemplate template;
    @Autowired
    private TokenService tokenService;



    public <R> R send(HttpMethod httpMethod, String uri, HttpEntity body, Class<R> responseType, Map<String, String> uriVariables){
        log.info("request: "+httpMethod+"  " + uri+ "  "+ body + "  "  );
        R response = null;
        switch (httpMethod) {
            case GET:
                response = this.template.getForObject(uri, responseType, uriVariables);
                break;
            case POST:
                response =  this.template.postForObject(uri, body, responseType, uriVariables);
                break;
            case HEAD:
                break;
            case PUT:
                break;
            case PATCH:
                break;
            case DELETE:
                break;
            case OPTIONS:
                break;
            case TRACE:
                break;
        }


        log.info("response: "+ response);
        return response;
    }

    //新增临时素材
    public String uploadMedia(){

        return "";
    }
    public String getMeida(){
        String token = tokenService.getToken();
        return "";
    }

}
